package game;

import java.util.Vector;

public class Vector3 {
    public double x, y, z;

    /**
     * @param x The x coordinate
     * @param y The y coordinate
     * @param z The z coordinate
     */
    public Vector3(double x, double y, double z){
        this.x = x; this.y = y; this.z = z;
    }

    /**
     * @param vec The Vector3 to copy
     */
    public Vector3(Vector3 vec){
        this.x = vec.x; this.y = vec.y; this.z = vec.z;
    }

    public double mod(){
        return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
    }

    public Vector3 normalized(){
        double mod = this.mod();
        if(mod > 0){
            return this.divide(mod);
        }
        return this;
    }

    public Vector3 add(Vector3 vec){
        return new Vector3(this.x + vec.x, this.y + vec.y, this.z + vec.z);
    }

    public Vector3 sub(Vector3 vec){
        return new Vector3(this.x - vec.x, this.y - vec.y, this.z - vec.z);
    }

    public Vector3 multiply(double f){
        return new Vector3(this.x *f, this.y *f, this.z *f);
    }

    public Vector3 divide(double f) {
        return new Vector3(this.x / f, this.y / f, this.z / f);
    }

    public Vector3 add(double n){
        return new Vector3(this.x + n, this.y + n, this.z);
    }//TODO: Ojo z

    /**
     * Return the result of substracting b from a
     * @param a
     * @param b
     * @return
     */
    public static Vector3 sub(Vector3 a, Vector3 b){
        return new Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
    }

    /**
     * Returns the distance between two Vector3 points
     * @param a
     * @param b
     * @return
     */
    public static double distance(Vector3 a, Vector3 b) {
        return Vector3.sub(a,b).mod();
    }

    /**
     * Returns the distance between two Vector3 points ignoring the z value
     * @param a
     * @param b
     * @return
     */
    public static double distance2d(Vector3 a, Vector3 b) {
        Vector3 dif = a.sub(b);
        dif.z = 0;
        return dif.mod();
    }


    public static boolean equal(Vector3 a, Vector3 b) {
        return a.x == b.x && a.y == b.y;
    }

    public static double dot(Vector3 a, Vector3 b) {return a.x*b.x+a.y*b.y+a.z*b.z;}//TODO: Ojo z
}
